import { defineStore } from 'pinia'
import { getUserInfo, getMenuList, getPermissionList } from '@/api'
import { resetRouter } from '@/router'
import store from '../index'

const getMeunList = (data) => [
  data.map((v) => {
    return {}
  })
]

export const userApp = defineStore('app', {
  state: () => ({
    keepAliveRoutes: new Set(),
    userInfo: '',
    menuList: [],
    permissionList: []
  }),
  getters: {},
  actions: {
    keepAliveRoutesPush(payload) {
      this.keepAliveRoutes.add(payload)
    },
    keepAliveRoutesDel(payload) {
      this.keepAliveRoutes.delete(payload)
    },
    keepAliveRoutesClear() {
      this.keepAliveRoutes.clear()
    },
    setUserInfo(payload: g.object) {
      this.userInfo = payload
    },
    async GetUserInfo() {
      const res = await getUserInfo(store.userStore.orgId)
      this.setUserInfo(res.data)
    },
    async GetMenuList() {
      const res = await getMenuList(store.userStore.platformId)
      this.menuList = resetRouter(res.data)
    },
    async GetPermissionList() {
      const res = await getPermissionList()
      this.permissionList = res.data
    }
  }
})
